<template>
  <wd-popup
    custom-class="cu-modal"
    customStyle="width: '90vw'"
    v-model="state.showDia"
    @close="hideModal"
  >
    <view class="cu-dialog bg-white" @tap.stop="">
      <view class="cu-bar flex items-center">
        <view class="action" @tap="hideModal">取消</view>
        <!-- <text class="action" style="margin-right: 30rpx; font-size: 30rpx" @tap="makeSure">
					确定
				</text> -->
      </view>
      <view class="content">
        <view style="display: flex; align-items: center; height: 60rpx; padding: 10rpx 40rpx">
          <wd-input
            v-model="state.queryForm.demandCode"
            clearable
            @input="onSearchInput"
            placeholder="需求单号"
          />
          <!-- <wd-input
            v-model="state.queryForm.schemeNo"
            clearable
            @input="onSearchInput"
            placeholder="方案单号"
            style="margin-left: 40rpx"
          /> -->
        </view>
        <view class="search-results table-container">
          <table class="analysis-table">
            <tbody>
              <tr>
                <th>需求单号</th>
                <th>需求产品</th>
                <th>产品规格</th>
              </tr>
              <tr
                align="center"
                v-for="(item, index) in state.dataList"
                :key="index"
                @tap="makeSure(item)"
              >
                <td>{{ item.demandCode }}</td>
                <td>{{ item.invName }}</td>
                <td>{{ item.invStd }}</td>
              </tr>
            </tbody>
          </table>
        </view>
      </view>
    </view>
  </wd-popup>
</template>

<script lang="ts" setup name="selectScheme">
import { getRdDemandPageNoTask } from '@/service/pm-requirement';

const emit = defineEmits(['hideModal', 'checkLeaguer']);

const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
});

const state = reactive({
  showDia: false,
  queryForm: {
    reviewStatus: 2,
    requestFlag: 1,
    taskAllStatus: 2,
  },
  dataList: [],
});

watch(
  () => props.show,
  (val) => {
    state.showDia = val;
    if (val) {
      onSearchInput();
    }
  },
  { immediate: true, deep: true },
);

const onSearchInput = (e?) => {
  const params = {
    ...state.queryForm,
    page: 1,
    limit: 200,
  };
  getRdDemandPageNoTask(params)
    .then((res) => {
      state.dataList = res.data.records;
    })
    .catch((err) => {});
};

const hideModal = () => {
  emit('hideModal');
  state.showDia = false;
};

const makeSure = (item) => {
  emit('checkLeaguer', item);
  hideModal();
};
</script>

<style scoped lang="scss">
@import './table';

.cu-dialog {
  width: 90vw;
  height: 80vh;
  padding: 10rpx 0;
  font-size: 26rpx;

  .cu-bar {
    // padding: 10rpx 20rpx;
    position: relative;
    align-items: center;
    justify-content: space-between;
    min-height: 50px;
    border-bottom: 1rpx solid #f1f1f1;

    .action {
      display: flex;
      align-items: center;
      justify-content: center;
      min-width: 50px;
      min-height: 50px;
      margin-right: 0;
      font-size: 30rpx;
    }
  }

  .content {
    .search-results {
      height: calc(100% - 110rpx);
      padding: 0 35rpx;
      margin-top: 30rpx;
    }
  }
}
</style>
